﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;

namespace Excel2DbTool.Converters
{
    public abstract class BooleanConverter<T> : IValueConverter
    {
        protected BooleanConverter(T trueValue, T falseValue)
        {
            this.TrueValue = trueValue;
            this.FalseValue = falseValue;
        }

        public T TrueValue { get; set; }

        public T FalseValue { get; set; }

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return Object.Equals(value, true) ? this.TrueValue : this.FalseValue;
        }
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return Object.Equals(value, this.TrueValue) ? true : false;
        }
    }

    public sealed class BooleanToOpacityConverter : BooleanConverter<int>
    {
        #region ctor
        static BooleanToOpacityConverter()
        {
        }
        private BooleanToOpacityConverter()
            : base(100, 0)
        {
        }
        #endregion

        private static BooleanToOpacityConverter converter;
        public static BooleanToOpacityConverter Instance
        {
            get { return converter ?? (converter = new BooleanToOpacityConverter()); }
        }
    }

    #region Visibility
    class BooleanToVisibilityConverter : BooleanConverter<Visibility>
    {
        #region ctor
        static BooleanToVisibilityConverter()
        {
        }
        private BooleanToVisibilityConverter()
            : base(Visibility.Visible, Visibility.Collapsed)
        {
        }
        #endregion

        private static BooleanToVisibilityConverter converter;
        public static BooleanToVisibilityConverter Instance
        {
            get { return converter ?? (converter = new BooleanToVisibilityConverter()); }
        }
    }

    class BooleanToVisibilityOppositeConverter : BooleanConverter<Visibility>
    {
        #region ctor
        static BooleanToVisibilityOppositeConverter()
        {
        }
        private BooleanToVisibilityOppositeConverter()
            : base(Visibility.Collapsed, Visibility.Visible)
        {
        }
        #endregion

        private static BooleanToVisibilityOppositeConverter converter;
        public static BooleanToVisibilityOppositeConverter Instance
        {
            get { return converter ?? (converter = new BooleanToVisibilityOppositeConverter()); }
        }
    }
    #endregion

    //#region Brush
    //class BoolToBrushConverter : BooleanConverter<Brush>
    //{
    //    private static BoolToBrushConverter converter;
    //    public static BoolToBrushConverter Instance
    //    {
    //        get { return converter ?? (converter = new BoolToBrushConverter()); }
    //    }

    //    private BoolToBrushConverter()
    //        : base(Colors.Blue, Colors.Red)  //true  蓝色   false 红色
    //    {
    //        //#FF00FF00
    //    }
    //}
    //#endregion
}
